
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>
        房产管理
    </title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <script src="js/jquery.js"></script>
<!--    <link rel="stylesheet" href="css/main.css" media="all">-->
<!--    <script type="text/javascript" src="lib/loading/okLoading.js"></script>-->
<!--    <link rel="stylesheet" href="css/bootstrap.css">-->
</head>
<body>
<div class="x-nav">
            <span class="layui-breadcrumb">
              <a><cite>首页</cite></a>
              <a><cite>房产管理</cite></a>
              <a><cite>房产列表</cite></a>
            </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"  href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <form class="layui-form x-center" action="" style="width:800px">
        <div class="layui-form-pane" style="margin-top: 15px;">
            <div class="layui-form-item">
<!--                <div class="layui-input-inline">-->
<!--                    <input class="layui-input" placeholder="截止日" name="LAY_demorange_e" id="LAY_demorange_e">-->
<!--                </div>-->
<!--                下拉框查询小区列表-->
                <div class="layui-input-inline" style="margin-left: 26px">
                    <select name="community_id" id="community_id" lay-verify="" lay-search>
                    </select>
                </div>
                <!--                下拉框查询楼栋列表-->
                <div class="layui-input-inline" style="margin-left: 26px">
                    <select name="building_id" id="building_id" lay-verify="building_id" lay-search>
                    </select>
                </div>
                <!--                下拉框查询单元楼列表-->
                <div class="layui-input-inline" style="margin-left: 26px">
                    <select name="unit_id" id="unit_id" lay-verify="building_id" lay-search>
                    </select>
                </div>

<!--                <div class="layui-input-inline" style="margin-left: 26px">-->
<!--                    <input type="text" name="username"  placeholder="输入业主姓名" autocomplete="off" class="layui-input">-->
<!--                </div>-->

                <div class="layui-input-inline" style="width:80px; posinset: absolute;left:500px;">
                    <button class="layui-btn"  lay-submit="" onclick="search()" lay-filter="sreach">
                        <i class="layui-icon">&#xe615;</i></button>
                </div>
            </div>
        </div>
    </form>
        <button class="layui-btn layui-btn-danger" onclick="delAll()">
            <i class="layui-icon">&#xe640;</i>批量删除
        </button>
        <button class="layui-btn" onclick="home_add('添加','homeadd.html','1000','600')">
            <i class="layui-icon">&#xe608;</i>添加
        </button>
        <!-- <span class="x-right" style="line-height:40px">共有数据：88 条</span> -->
    <table class="layui-table" lay-filter="table" id="app"></table>

    <div id="page"></div>
</div>
<script src="js/layui-v2.7.6/layui/layui.js" type="text/javascript" charset="utf-8"></script>
<link rel="stylesheet" type="text/css" href="js/layui-v2.7.6/layui/css/layui.css"/>
<script src="js/jquery.js"></script>
<script src="js/x-layui.js" type="text/javascript" charset="utf-8"></script>
<script src="js/axios.js"></script>
<script>

    var pageSize = 2;
    var pageNum= 1 ;

    //列表初始化
    search(pageNum,pageSize);
    //所属小区下拉框回显
    function getCommunity_id(community_id) {
        $.ajax({
            type:"GET",//请求类型
            url:"../community/find",
            dataType:"json",
            success:function (data) {
                var optiongs ="<option value='0'>请选择所属小区</option>";
                $("#community_id").html("");
                layui.form.render("select");
                for (var i = 0; i <data.data.length ; i++) {
                    if (community_id == data.data[i].id && community_id !=null){
                        optiongs +="<optiong selected value =\"" +data.data[i].id +"\" class>"+data.data[i].name +"</optiong>";
                    } else{
                        optiongs += "<option value=\"" +data.data[i].id + "\" class>" +data.data[i].name+"</option>";
                    }
                }
                $("#community_id").append(optiongs);
                layui.form.render("select");
            },
            error :function (data) {
                alert("所属加载小区失败!");
            }
        });
    }

    function compareDate(date1, date2) {
        var oDate1 = new Date(date1);
        var oDate2 = new Date(date2);
        if (date1 != '' && date2 != '') {
            if (oDate1.getTime() > oDate2.getTime()) {
                return true; //第一个大
            } else {
                return false; //第二个大
            }
        } else {
            return false;
        }
    }

    //查询方法
    function search(num,size) {
        var new_community_id = $("#community_id").val();
        // var new_building_id=$("#building_id").val();
        // var new_unit_id=$("#unit_id").val();

        var searchMap = {
            "community_id": new_community_id,
            "pageNum": (num - 1) * size,
            "pageSize": size
        };

        // if (compareDate(new_LAY_demorange_s, new_LAY_demorange_e)) {
        //     $("#LAY_demorange_s").val("");
        //     $("LAY_demorange_e").val("");
        //     layer.msg("开始日不能大于截止日!")
        //     search(num, size);
        // }
        axios.post("/homelist/search",searchMap).then((res) => {
            layui.use(['laydate', 'element', 'laypage', 'form', 'layer', 'table'], function () {
                var laydate = layui.laydate;//日期插件
                var element = layui.element;//面包导航
                var laypage = layui.laypage;//分页插件
                var layer = layui.layer;//弹出层
                var table = layui.table;
                var form = layui.form;
                $ = layui.jquery;
                //执行table实例
                table.render({
                    elem:'#app',
                    height:420,
                    data:res.data.data,
                    title:'',
                    toolbar:'#toolbarDelAdd',
                    totalRow:true,
                    cols: [[ //表头
                        {type: 'checkbox'}
                        , {field: 'id', title: 'ID', sort: true, align: "center"}
                        , {field: 'cname', title: '所属小区', align: "center"}
                        , {field: 'code', title: '小区编号', sort: true, align: "center"}
                        , {field: 'bname',title:'栋数名',sort: true,align: "center"}
                        , {field: 'huname', title: '单元', sort: true, align: "center"}
                        , {field: 'oname',title: '业主姓名',sort: true,align: "center"}
                        , {field: 'area', title:'室内面积', sort: true ,align: "center"}
                        , {field: 'roomNum',title: '房间数量',sort: true, align: "center"}
                        , {
                            field: 'createTime', title: '入住时间', sort: true, align: "center", templet: function (res) {
                                return layui.util.toDateString(res.createTime, 'yyyy-MM-dd HH:mm:ss')
                            }
                        }
                        // 
                        , {
                            field: 'sign', title: '操作', align: "center", templet: function (resp) {
                                return ' <a title="编辑" href="javascript:;" onclick="home_edit(\'编辑\',\'park_add.html\','+resp.id+',\'\',\'510\')"' +
                                    '       class="ml-5" style="text-decoration:none">' +
                                    '        <i class="layui-icon">&#xe642;</i>' +
                                    '    </a>' +
                                    '    <a title="删除" href="javascript:;" onclick="home_del(this,'+resp.id+')"' +
                                    '       style="text-decoration:none">' +
                                    '        <i class="layui-icon">&#xe640;</i>' +
                                    '    </a>'
                            }
                        }
                    ]]
                });
                console.log(res.data.data)

                //分页初始化
                laypage.render({
                    elem: 'page' //分页容器的id
                    , count: res.data.total //数据总数
                    , limit: pageSize //每页显示的数据条数
                    , curr: pageNum
                    , skin: '#1E9FFF' //自定义选中色值
                    , layout: ['prev', 'page', 'next', 'count', 'limit', 'refresh', 'skip'] //自定义排版
                    , jump: function (obj, first) {
                        if (!first) {
                            layer.msg('第' + obj.curr + '页', {offset: 'b'});
                            pageNum = obj.curr;
                            pageSize = obj.limit;
                            search(pageNum, pageSize);
                        }
                    }
                });
                //日期初始化
                // laydate.render({
                //     elem: "#LAY_demorange_s",
                //     type: "date"
                //     , max: 0
                //     , istoday: false
                // });
                //
                // laydate.render({
                //     elem: "#LAY_demorange_e",
                //     type: "date"
                //     , max: 0
                //     , istoday: false
                // });

                table.on("toolbar(table)", function (obj) {
                    if (obj.event == "delAll") {
                        layer.confirm('确认要删除吗？', function () {
                            var checkStatus = table.checkStatus(obj.config.id);
                            var ids = [];
                            axios.post("homelist/del", ids).then((rels) => {
                                if (rels.code = 2000) {
                                    layer.msg('删除成功');
                                    var total = res.data.total;  //总数
                                    var sun = total - obj.config.data.length;
                                    // var s_total=total%pageSize==0?total/pageSize:total/pageSize+1;
                                    var e_total = sun % pageSize == 0 ? sun / pageSize : sun / pageSize + 1;
                                    search(pageNum <= e_total ? pageNum : pageNum - 1, pageSize);
                                } else {
                                    layer.msg("删除失败")
                                }
                            })
                        })
                    }
                })
            });
            getCommunity_id(new_community_id)
        })
    }
    function question_show(argument) {
        layer.msg('可以跳到前台具体问题页面', {icon: 1, time: 1000});
    }

    /*添加*/
    function home_add(title, url, w, h) {
        x_admin_show(title, url, w, h);
    }

    //编辑
    function home_edit(title, url, id, w, h) {
        url = url + "?id=" + id;
        x_admin_show(title, url, w, h);
    }

    /*根据id删除*/
    function home_del(obj, id) {
        layer.confirm('确认要删除吗？', {icon: 3, title: '提示信息'}, function (index) {
            $.ajax({
                type: "post",
                url: "../homelist/delById",
                data: {id: id},
                dataType: "json",
                success: function (data) {
                    // console.log(data)
                    if (data.code == 2000) {
                        //发异步删除数据
                        $(obj).parents("tr").remove();
                        layer.msg("删除成功", {icon: 6, time: 1000});
                        // setTimeout(function () {
                        //     window.location.reload();
                        // }, 1000);
                        return false;
                    } else if (data.code == 2001) {
                        layer.msg(data.message, {icon: 2, time: 2000})
                        return false;
                    } else {
                        layer.msg("删除成功", {icon: 5, time: 1000});
                        return false;
                    }
                },
                error: function (err) {
                    layer.msg(err.message, {icon: 2, time: 2000})
                    return false;
                }
            });
            // //发异步删除数据
            // $(obj).parents("tr").remove();
            // layer.msg('已删除!', {icon: 1, time: 1000});
        });
    }

</script>

</body>
</html>